Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse blocks in html! as Rust block expressions #3466

Conversation

its-the-shrimp
Copy link
Contributor

Description

Makes the syntax of html! more consistent with Rust syntax by parsing the Rust code in {} not as 1 expression but as a sequence of statements delimited by ;, with the last one optionally omitting it. Docs are updated appropriately.
.gitignore is also updated to exclude npm artifacts, just for convenience.

Checklist

  • I have reviewed my own code
  • I have added tests

@github-actions
Copy link

github-actions bot commented Oct 13, 2023

Visit the preview URL for this PR (updated for commit b58d22e):

https://yew-rs--pr3466-parse-braces-in-html-djhpnl4x.web.app

(expires Fri, 20 Oct 2023 20:17:19 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Oct 13, 2023

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 102.813 102.813 0 0.000%
boids 175.744 175.744 0 0.000%
communication_child_to_parent 95.287 95.287 0 0.000%
communication_grandchild_with_grandparent 109.031 109.031 0 0.000%
communication_grandparent_to_grandchild 105.690 105.690 0 0.000%
communication_parent_to_child 92.757 92.757 0 0.000%
contexts 113.419 113.419 0 0.000%
counter 89.170 89.170 0 0.000%
counter_functional 89.905 89.905 0 0.000%
dyn_create_destroy_apps 92.340 92.340 0 0.000%
file_upload 103.496 103.496 0 0.000%
function_memory_game 174.743 174.743 0 0.000%
function_router 352.409 352.409 0 0.000%
function_todomvc 163.494 163.494 0 0.000%
futures 227.829 227.829 0 0.000%
game_of_life 112.247 112.247 0 0.000%
immutable 188.934 188.934 0 0.000%
inner_html 85.955 85.955 0 0.000%
js_callback 113.388 113.388 0 0.000%
keyed_list 201.064 201.064 0 0.000%
mount_point 89.161 89.161 0 0.000%
nested_list 115.838 115.838 0 0.000%
node_refs 96.269 96.269 0 0.000%
password_strength 1721.082 1721.082 0 0.000%
portals 98.372 98.372 0 0.000%
router 318.407 318.407 0 0.000%
simple_ssr 144.056 144.056 0 0.000%
ssr_router 390.164 390.164 0 0.000%
suspense 119.003 119.003 0 0.000%
timer 91.771 91.771 0 0.000%
timer_functional 100.472 100.472 0 0.000%
todomvc 143.779 143.779 0 0.000%
two_apps 89.871 89.871 0 0.000%
web_worker_fib 138.854 138.854 0 0.000%
web_worker_prime 190.373 190.373 0 0.000%
webgl 88.526 88.526 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link

github-actions bot commented Oct 13, 2023

Benchmark - SSR

Yew Master

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 377.602 377.842 377.709 0.089
Hello World 10 647.339 664.154 651.246 4.731
Function Router 10 2188.754 2228.624 2219.407 12.323
Concurrent Task 10 1006.830 1008.112 1007.565 0.371
Many Providers 10 1568.458 1619.180 1588.321 17.632

Pull Request

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 376.841 377.799 377.531 0.262
Hello World 10 637.941 659.311 645.623 5.647
Function Router 10 2191.828 2220.444 2203.372 8.487
Concurrent Task 10 1006.568 1007.789 1007.353 0.432
Many Providers 10 1564.309 1709.510 1589.010 43.096

@ranile
Copy link
Member

ranile commented Oct 13, 2023

What benefit does this have? I only see the drawback of encouraging people writing Rust code inside html!. Rustfmt can't format that code so we decided to encourage users to keep Rust keep out of html!.

@its-the-shrimp
Copy link
Contributor Author

its-the-shrimp commented Oct 13, 2023

I implemented this after having had to write {{}} time and time again in my own code, why should the framework assume usage of any external tool besides the Rust compiler itself? I believe that if the framework can allow for more concise code, then it should allow it, besides, there are no direct downsides to this expansion of syntax, and it's backwards-compatible.

@futursolo
Copy link
Member

futursolo commented Oct 14, 2023

I also do not think it should be supported. {} is the interpolation syntax and not block expression, where an expression is expected within an interpolation identifier.

The current pattern promotes <tag>({expr}*)</tag> instead of <tag>(block_expr*)</tag>.

This makes html! to be on par of what format! wants to do for expressions.
(Rust planned to allow {(expr)} for format! but not {((stmt*)expr)}.)

See: https://github.com/rust-lang/rfcs/blob/master/text/2795-format-args-implicit-identifiers.md#alternative-solution---interpolation

@futursolo futursolo mentioned this pull request Oct 29, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants